package com.admin.controller.system;

import com.admin.controller.base.BaseController;
import com.admin.service.OssUtilsService;
import com.admin.service.UploadService;
import com.admin.vo.ResultVO;
import com.admin.vo.upload.UploadVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


/**
 * 上次接口
 */
@RestController
@RequestMapping(value = "/upload")
@Api(description = "公共上传接口")
public class UploadController extends BaseController {

    @Autowired
    private UploadService uploadService;

    @Autowired
    private OssUtilsService ossUtilsService;

    @PostMapping("/file")
    @ApiOperation("上传单个文件")
    public ResultVO<UploadVO> uploadFile(
        @ApiParam(required = true, name = "file", value = "文件流") @RequestParam("file") MultipartFile file) {
    	return uploadService.uploadFileForOSS(file, "files");
    }

    @PostMapping("/fileNew")
    @ApiOperation("上传单个文件")
    public ResultVO<UploadVO> uploadFileNew(
            @ApiParam(required = true, name = "file", value = "文件流") @RequestParam("file") MultipartFile file) {
        return uploadService.uploadFileForOSS(file, "files");
    }


    @GetMapping("/referer")
    @ApiOperation("防盗链信息")
    public ResultVO<List<String>> referer() {
        return ResultVO.ok(ossUtilsService.getRefererList());
    }


    @GetMapping("/delReferer")
    @ApiOperation("防盗链信息")
    public ResultVO<Boolean> delReferer() {
        return ResultVO.ok(ossUtilsService.delReferer());
    }

    @PostMapping("/setReferer")
    @ApiOperation("设置防盗链")
    public ResultVO<Boolean> setReferer(@RequestBody List<String> list) {
        return ResultVO.ok(ossUtilsService.setReferer(list));
    }




}
